package com.ysq.tankgame;

/* 
 * 子弹类
 */

public class Shot implements Runnable {
    private int x; // 子弹的横坐标
    private int y; // 子弹的纵坐标
    private int direct; // 子弹的方向
    private int speed; // 子弹的速度
    private boolean isLive = true; //子弹是否存活

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
        this.speed = 5;
    }

    @Override
    public void run() {

        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            switch (direct) {
                case 0: // 向上
                    y -= speed;
                    break;
                case 1: // 向右
                    x += speed;
                    break;
                case 2: // 向下
                    y += speed;
                    break;
                case 3: // 向左
                    x -= speed;
                    break;
            }

            if (!(x > 0 && x < 1000 && y > 0 && y < 750 && isLive)) {
                isLive = false;
                break;
            }
        }
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean isLive) {
        this.isLive = isLive;
    }

    @Override
    public String toString() {
        return "Shot [x=" + x + ", y=" + y + ", direct=" + direct + ", speed=" + speed + ", isLive=" + isLive + "]";
    }
    

    
    
    
}
